package com.pm2.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.pm2.dao.personnel.DeveloperDao;
import com.pm2.dao.plan.DayPlanDao;
import com.pm2.dao.plan.MasterPlanDao;
import com.pm2.entity.plan.MasterPlan;
import com.pm2.entity.plan.PlanMenu;
import com.pm2.service.plan.MasterPlanService;
import com.shuohe.util.returnBean.ReturnBean;

@Service
public class MasterPlanServiceImpl implements MasterPlanService{

	@Autowired
	private MasterPlanDao masterPlanDao; 
	
	@Autowired
	private DayPlanDao dayPlanDao; 
	
	@Autowired
	private DeveloperDao developerDao; 
	
	
	@Override
	public ReturnBean deleteMasterPlan(int id) {
		//删除主计划
		masterPlanDao.deleteById(id);
		//删除主计划相关开发者
		developerDao.deleteByMasterPlanId(id);
		//删除日计划
		dayPlanDao.deleteByPid(id);
		return new ReturnBean(true,"删除成功");
	}


	@Override
	public List<PlanMenu> findByProjectId(int project_id) {
		// TODO Auto-generated method stub
		List<PlanMenu> lm = new ArrayList<PlanMenu>();
		List<MasterPlan> list = masterPlanDao.findByProjectId(project_id);
		System.out.println(list);
		for (MasterPlan masterPlan : list) {
			List<PlanMenu> list2 = new ArrayList<PlanMenu>();
			List<PlanMenu> list3 = new ArrayList<PlanMenu>();
			PlanMenu pm1 = new PlanMenu();
			PlanMenu pm2 = new PlanMenu();
			PlanMenu pm3 = new PlanMenu();
			if(null!=masterPlan.getTask_level_3() && "0".equals(masterPlan.getTask_level_3_state())) {
				pm3.setId(masterPlan.getId());
				pm3.setText(masterPlan.getTask_level_3());
				pm3.setLevel(3);
				list3.add(pm3);
			}
			if(null!=masterPlan.getTask_level_2() && "0".equals(masterPlan.getTask_level_2_state())) {
				pm2.setId(masterPlan.getId());
				pm2.setText(masterPlan.getTask_level_2());
				pm2.setLevel(2);
				list2.add(pm2);
				pm2.setChildren(list3);
			}
			if(null!=masterPlan.getTask_level_1() && "0".equals(masterPlan.getTask_level_1_state())) {
				pm1.setId(masterPlan.getId());
				pm1.setText(masterPlan.getTask_level_1());
				pm1.setLevel(1);
				pm1.setChildren(list2);
				lm.add(pm1);
			}
			
		}
		System.out.println(lm);
		return lm;
	}



}
